SmartShape.prototype = new ShapeBase;
function SmartShape(scene){
	this.base = ShapeBase; this.base(scene);
	
	this.geometry = null;

	this.applyGeometry = function(geometry){
		this.geometry = geometry;
		
		this.vertexBuffer = geometry.getVertexBuffer(this.context);
	}
	
	this.addToScene = function(scene){
		if(scene) this.scene = scene;
		this.scene.addShape(this);
	}
	
	this.draw = function(){
		if(!this.vertexBuffer){
			// nothing to draw
			return;
		}
		if(!this.colorBuffer){
			// colors were not set
			this.initRandomColors();
		}
		this.scene.mvMatrix =  mat4.create();
		mat4.identity(this.scene.mvMatrix);
				
		// draw according to camera position				
		mat4.translate(this.scene.mvMatrix, [-this.scene.cameraPosition.x, -this.scene.cameraPosition.y, -this.scene.cameraPosition.z]);
		mat4.rotate(this.scene.mvMatrix, this.scene.cameraAngles.x * Math.PI / 180, [-1, 0, 0]);
		mat4.rotate(this.scene.mvMatrix, this.scene.cameraAngles.y * Math.PI / 180, [0, -1, 0]);
		mat4.rotate(this.scene.mvMatrix, this.scene.cameraAngles.z * Math.PI / 180, [0, 0, -1]);			
		
		// draw to the object's real position
		//console.log(JSON.stringify([this.position.x, this.position.y, this.position.z]));
		mat4.translate(this.scene.mvMatrix, [this.position.x, this.position.y, this.position.z]);
		
		
		var animations =  this.animations.sort(function(a, b){return a.order-b.order});
		for(var i=0;i<animations.length;i++){
			//debugger;
			animations[i].execute(this);
		}
		
		this.vertexBuffer.bind();
		this.context.vertexAttribPointer(this.scene.drawingShader.vertexPositionAttribute, this.vertexBuffer.itemSize, this.context.FLOAT, false, 0, 0);
		
		this.colorBuffer.bind();
		this.context.vertexAttribPointer(this.scene.drawingShader.vertexColorAttribute, this.colorBuffer.itemSize, this.context.FLOAT, false, 0, 0);
		
		this.setMatrixUniforms();
		
		this.context.drawArrays(this.context.TRIANGLES, 0, this.vertexBuffer.itemsCount);
		/*
		if(this.vertices){
			this.context.bindBuffer(this.context.ARRAY_BUFFER, this.vertexBuffer);
			this.context.vertexAttribPointer(this.scene.shaderProgram.vertexPositionAttribute, this.vertexBuffer.itemSize, this.context.FLOAT, false, 0, 0);
		}
		if(this.verticeColors){
			this.context.bindBuffer(this.context.ARRAY_BUFFER, this.colorsBuffer);
			this.context.vertexAttribPointer(this.scene.shaderProgram.vertexColorAttribute, this.colorsBuffer.itemSize, this.context.FLOAT, false, 0, 0);
		}
		//debugger;
		this.scene.setMatrixUniforms();
		this.context.drawArrays(this.context.TRIANGLES, 0, this.vertexBuffer.numItems);
		//this.context.drawElements(this.context.TRIANGLES, this.vertexBuffer.numItems, this.context.UNSIGNED_SHORT, 0);
		*/
	}
}